package com.liyu.iblog.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.PrePersist;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@SuppressWarnings("serial")
@Entity
public class Tag implements DomainObject {
   
    @Id
    private Key key;
    
    private String id;
    
    private String name;
    
    @Basic(fetch = FetchType.EAGER)
    private List<Key> blogKeys = new ArrayList<Key>();
    
    public Tag() {
        
    }

    @PrePersist
    public void prePersist() {
        key = KeyFactory.createKey(this.getClass().getSimpleName(), id);
    }
    
    public Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Key> getBlogKeys() {
        return blogKeys;
    }

    public void setBlogKeys(List<Key> blogKeys) {
        this.blogKeys = blogKeys;
    }
    
    public void addBlogKey (Key key) {
        blogKeys.add(key);
    }
    
    public void removeBlogKey (Key key) {
        blogKeys.remove(key);
    }
}
